<script setup>
import { useCategoryStore } from '@/stores/categoryStore'
const categoryStore = useCategoryStore()
</script>

<template>
  <div class="home-category">
    <ul class="menu">
      <li class="cate-menu-item" v-for="item in categoryStore.categoryList" :key="item.id">
        <RouterLink :to="`/category/${item.id}`">{{item.name}}</RouterLink>
        <RouterLink v-for="i in item.children.slice(0,2)" :key="i" :to="`/category/sub/${i.id}`">{{i.name}}</RouterLink>
        <!--弹层位置-->
        <div class="layer">
          <h4>分类推荐 <small>根据您的购买或浏览记录推荐</small></h4>
          <ul>
            <li v-for="i in item.goods" :key="i.id">
              <RouterLink to="/">
                <img :src="i.picture" />
                <div class="info">
                  <p class="name ellipis-2">
                    <span class="txt-clamp" data-clamp='2'>{{i.name}}</span>
                  </p>
                  <p class="desc ellipis">
                    <span class="txt-clamp">{{i.desc}}</span>
                  </p>
                  <p class="price"><i>￥</i>{{i.price}}</p>
                </div>
              </RouterLink>
            </li>
          </ul>
        </div>
      </li>
    </ul>
  </div>
</template>

<style lang="scss" scoped>
.home-category{
  width: 250px;
  height: 500px;
  background: rgba(0,0,0,.8);
  position: relative;
  z-index: 99;
  .menu{
    .cate-menu-item{
      padding-left: 40px;
      height: 50px;
      line-height: 50px;
      transition-property: background-color;
      transition-duration: 0.3s;
      &>a{
        margin-right: 4px;
        color: #fff;
        &:first-child{
          font-size: 16px;
        }
        &:hover{
          text-decoration: underline;
        }
      }
      &:hover{
        background-color: $xtxColor;
      }
      &:hover .layer{
        display: block;
      }
    }
  }
  .layer{
    width: 990px;
    height: 500px;
    //background: hsla(0,0%,100%,.8);
    background-color: rgba(255,255,255,.8);
    position: absolute;
    left: 250px;
    top: 0;
    display: none;
    padding: 0 15px;
    h4{
      font-size: 20px;
      font-weight: 400;
      line-height: 80px;
      color: #333;
      small{
        font-size: 16px;
        color: #666;
      }
    }
    ul{
      display: flex;
      flex-wrap: wrap;
      li{
        width: 33.333%;
        padding: 10px;
        a{
          display: flex;
          background-color: #fff;
          border: 1px solid #ededed;
          border-radius: 4px;
          padding: 10px;
          img{
            width: 96px;
            height: 96px;
            object-fit: cover;
          }
          .info{
            flex: 1 1 auto;
            padding-left: 10px;
          }
        }
        .name{
          line-height: 1.5;
          height: 51px;
          font-size: 16px;
          font-weight: bold;
          color: #333;
          transition-property: background-color,color;
          transition-duration: 0.3s;
          span{
            width: 100%;
            display: -webkit-box;
            overflow: hidden;
            text-overflow: ellipsis;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
          }
          &:hover{
            color: $xtxColor;
          }
        }
        .desc span{
          width: 100%;
          display: -webkit-box;
          overflow: hidden;
          text-overflow: ellipsis;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 1;
          font-size: 14px;
          color: #666;
          line-height: 22px;
        }
        .price{
          line-height: 1;
          font-size: 18px;
          color: $priceColor;
          margin-top: 5px;
        }
      }
    }
  }
}
</style>